﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Xps.Packaging;

namespace BaseUi
{
    public static class Print
    {
        public static void InvokePrint(string printFileName)
        { // 打印对话框，设置属性
            System.Windows.Controls.PrintDialog pDialog = new System.Windows.Controls.PrintDialog();
            pDialog.PageRangeSelection = System.Windows.Controls.PageRangeSelection.AllPages;
            pDialog.UserPageRangeEnabled = true;
            // 这里你还可以设置对话框的MaxPage, MinPage, PageRange, PrintableAreaHeight, PrintableAreaWidth, PrintQueue, PrintTicket属性值等。 
            // 显示对话框，如果用户点击“打印”按钮，则返回true。
            Nullable<Boolean> print = pDialog.ShowDialog();
            if (print == true)
            {
                XpsDocument xpsDocument = new XpsDocument(printFileName, FileAccess.ReadWrite);
                System.Windows.Documents.FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
                pDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print");
            }
        }
    }
}
